package com.leigang.monitor.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leigang.common.parent.pojo.dto.ServerMonitorDto;
import com.leigang.common.parent.utils.IdUtils;
import com.leigang.monitor.dao.IServerMonitorMapper;
import com.leigang.monitor.entity.ServerMonitor;
import com.leigang.monitor.service.IServerMonitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author leig-a
 * @version 1.0
 * @desc
 * @date 2023/2/17 9:19
 */
@Slf4j
@Service
public class ServerMonitorServiceImpl extends ServiceImpl<IServerMonitorMapper, ServerMonitor> implements IServerMonitorService {


    @Override
    public List<ServerMonitor> listServerMonitor() {
        return list();
    }

    @Override
    public boolean insertServerMonitor(ServerMonitorDto serverMonitorDto) {
        log.info("ServerMonitorServiceImpl insertServerMonitor serverMonitorDto:{}", serverMonitorDto);
        ServerMonitor serverMonitor = new ServerMonitor();
        BeanUtil.copyProperties(serverMonitorDto, serverMonitor);
        String configId = IdUtils.generate();
        serverMonitor.setId(IdUtils.generate());
        serverMonitor.setServerId(configId);
        boolean saveFlag = save(serverMonitor);
        log.info("ServerMonitorServiceImpl insertServerMonitor saveFlag:{}", saveFlag);
        return saveFlag;
    }
}
